package com.mobiusws.reports.action;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DownloadAction extends ActionSupport {

	private static final long serialVersionUID = 4678058385584427297L;

	private String filename;

	public InputStream getInputStream() {
		InputStream inStream=null;
		try {
			System.out.println(filename);
			inStream = new FileInputStream(filename);
		} catch (FileNotFoundException e) {
//			inStream = new ByteArrayInputStream(
//					"File not found!".getBytes());
			e.printStackTrace();
		}
		
		return inStream;
	}

	public void setFilename(String filename) {
		this.filename=filename;
	}

	public String getFilename() {
		int idx=filename.lastIndexOf(File.separator);
		return filename.substring(idx+1, filename.length());
	}
	
	@Override
	public String execute() throws Exception {
		File file=new File(filename);
		return file.exists() ? SUCCESS : "fileNotFound";
	}
}
